<?php
	extract($_POST);
  	require('db.php');
	//selection of the id_user
	$sql = "SELECT id FROM dextrob_user WHERE login LIKE '".$login."' AND pass LIKE '".$pass."'";
	$req = mysql_query($sql) or die($alerte = "-1");
	$data = mysql_fetch_assoc($req);
	$id_user = $data['id'];
	//selection of the last id_value
	$sql2 = "SELECT id_value FROM dextrob_insulin WHERE id_user = '".$id_user."' ORDER BY id_value DESC";
	$req2 = mysql_query($sql2) or die($alerte = "-2");
	$nbr = mysql_num_rows($req2);
	if($nbr == 0){
		$new_id = 1;
	}else{
		$data2 = mysql_fetch_assoc($req2);
		$new_id = $data2['id_value'] + 1;
	}
	//add the value
  	$sql3 = "INSERT INTO dextrob_insulin (id_user, id_value, date, value, type) VALUES ('".$id_user."', '".$new_id."', '".$date."', '".$value."', '".$type."')";
  	mysql_query($sql3) or die($alerte = "-3");//or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
	//$data3 = mysql_num_rows($req3);
	
	$alerte = $new_id;
	echo $alerte;
?>